//歌单列表
<template>
    <div class="musicList">
        <div class="musicList-top">
            <div class="title">发现好歌单</div>
            <div class="more">查看更多</div>
        </div>
        <div class="mlist">
            <div class="container" id='musicSwiper'>
                <div class="swiper-wrapper">
                    <!-- 歌单列表,传入id -->
                    <router-link :to="{path:'/listview',query:{id:item.id}}" class="swiper-slide" v-for="(item,index) in musicList" :key="index">
                        <img :src="item.picUrl" alt="item.name">
                        <div class="name">{{item.name}}</div>
                        <div class="count"><span class="iconfont icon-bofang"></span>{{changeValue(item.playCount)}}</div>
                    </router-link>
                </div>
            </div>
         </div>
    </div>
</template>

<script>
import 'swiper/css/swiper.css'
import Swiper from 'swiper'
import {getMusicList} from '../api/index';
export default {
    data() {
        return {
            musicList:[]
        }
    },
    methods: {
        // 过滤播放次数，万为单位
        changeValue(num) {
            var res=0;
            if(num>=10000){
                res = num/10000
                res = res.toFixed(2) + "万"
            }
            return res
        }
    },


    async mounted() {
        let res = await getMusicList()
        // 打印出歌单数据
        // console.log(res.data);
        this.musicList = res.data.result
    },
    updated() {
        // 歌单10个展示3个
        const swiper = new Swiper('#musicSwiper', {
            slidesPerView: 3,
            spaceBetween: 10,
        });
    },
}
</script>


<style lang="less" scoped>
.musicList{
    width: 7.5rem;
    padding: 0.4rem;
    overflow: hidden;
    .musicList-top{
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 0.5rem;
        .title{
            font-size: 0.4rem;
            font-weight: 900;
        }
        .more{
            font-size: 0.25rem;
            border: 0.05rem solid #ccc;
            border-radius: 0.2rem;
            height: 0.5rem;
            padding: 0.05rem;
        }
    }
    .mlist{
        .container{
            width: 100%;
            height: 3rem;
            .swiper-wrapper{
                 .swiper-slide {
                     color: #000;
                     text-decoration: none;
                    display: flex;
                    flex-direction: column;
                    overflow: hidden;
                    position: relative;
                    img{
                        width: 100%;
                        height: auto;
                        border-radius: 0.1rem;
                    }
                    .name{
                        font-size: 0.25rem;
                        line-height: 0.4rem;
                    }
                    .count{
                        position: absolute;
                        right: 0.1rem;
                        top: 0.2rem;
                        font-size: 0.2rem;
                        color: #ccc;
                    }
                }
            }
        }
    }
}
</style>